import { ResPage, ResultData } from "@/api/interface/index";
import { UnitManage } from "@/api/interface";
import http from "@/api";

/**
 * @name 单位管理模块
 */

// 获取单位列表
export const getUnitList = (params: UnitManage.ReqUnitParams) => {
  return http.get<ResPage<UnitManage.ResUnitList>>(`/unit-manage/list`, params);
};

// 创建单位
export const createUnit = (params: UnitManage.ReqCreateUnit) => {
  return http.post<ResultData<number>>(`/unit-manage/create`, params);
};

// 更新单位
export const updateUnit = (params: UnitManage.ReqUpdateUnit) => {
  return http.put<ResultData>(`/unit-manage/update`, params);
};

// 删除单位
export const deleteUnit = (params: { id: number }) => {
  return http.delete<ResultData>(`/unit-manage/${params.id}`);
};

// 批量删除单位
export const batchDeleteUnit = (params: { ids: number[] }) => {
  return http.delete<ResultData>(`/unit-manage/batch`, params);
};

// 根据ID获取单位详情
export const getUnitById = (id: number) => {
  return http.get<ResultData<UnitManage.ResUnitList>>(`/unit-manage/${id}`);
};

// 根据单位编码获取单位
export const getUnitByCode = (unitCode: string) => {
  return http.get<ResultData<UnitManage.ResUnitList>>(`/unit-manage/code/${unitCode}`);
};

// 获取所有启用的单位
export const getAllEnabledUnits = () => {
  return http.get<ResultData<UnitManage.ResUnitList[]>>(`/unit-manage/all-enabled`);
};

// 根据单位类型获取单位列表
export const getUnitsByType = (unitType: string) => {
  return http.get<ResultData<UnitManage.ResUnitList[]>>(`/unit-manage/type/${unitType}`);
};

// 获取所有基础单位
export const getBaseUnits = () => {
  return http.get<ResultData<UnitManage.ResUnitList[]>>(`/unit-manage/base-units`);
};

// 根据单位类型获取基础单位
export const getBaseUnitsByType = (unitType: string) => {
  return http.get<ResultData<UnitManage.ResUnitList[]>>(`/unit-manage/base-units/type/${unitType}`);
};